﻿@{
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="format-detection" content="telephone=no" />
    <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" />
    <title>天猫淘宝内部优惠券</title>
    <link rel="stylesheet" href="/zhekou/css/common.css" />
    <link rel="stylesheet" href="/zhekou/css/zhekou.css?v=20170317" />
    <script type="text/javascript" src="http://cdn.bootcss.com/fastclick/1.0.6/fastclick.min.js"></script>
    <script type="text/javascript" src="http://cdn.bootcss.com/zepto/1.2.0/zepto.min.js"></script>
    <script type="text/javascript" src="/zhekou/js/common.js"></script>
</head>
<body>
    <div class="wrapper">
        <div class="top-menu-container">
            <div class="top-menu">
                <div class="inner">
                    <a class="top-menu-item active" data-tab-index="1" data-cate-id="0">今日推荐</a>
                    <a class="top-menu-item" data-tab-index="2" data-cate-id="1">女装</a>
                    <a class="top-menu-item" data-tab-index="3" data-cate-id="7">母婴</a>
                    <a class="top-menu-item" data-tab-index="4" data-cate-id="6">美妆</a>
                    <a class="top-menu-item" data-tab-index="5" data-cate-id="12">居家百货</a>
                    <a class="top-menu-item" data-tab-index="6" data-cate-id="4">配饰</a>
                    <a class="top-menu-item" data-tab-index="7" data-cate-id="8">美食</a>
                    <a class="top-menu-item" data-tab-index="8" data-cate-id="5">运动</a>
                    <a class="top-menu-item" data-tab-index="9" data-cate-id="13">家电</a>
                    <a class="top-menu-item" data-tab-index="10" data-cate-id="10">数码</a>
                    <a class="top-menu-item" data-tab-index="11" data-cate-id="2">男装</a>
                    <a class="top-menu-item" data-tab-index="12" data-cate-id="9">内衣</a>
                    <a class="top-menu-item" data-tab-index="13" data-cate-id="3">鞋包</a>
                    <a class="top-menu-item" data-tab-index="14" data-cate-id="11">家装</a>
                    <a class="top-menu-item" data-tab-index="15" data-cate-id="14">汽车</a>
                    <a class="top-menu-item" data-tab-index="16" data-cate-id="15">生活服务</a>
                    <a class="top-menu-item" data-tab-index="17" data-cate-id="16">图书音像</a>
                    <a class="top-menu-item" data-tab-index="18" data-cate-id="17">游戏话费</a>
                    <a class="top-menu-item" data-tab-index="19" data-cate-id="64">其它</a>
                </div>
            </div>
            <div class="sort-option-area">
                <ul>
                    <li data-type="0" class="active">综合
                    <li data-type="1">销量
                    <li data-type="3">优惠率
                    <li data-type="2">价格
                </ul>
            </div>
        </div>

        <div class="recommend-section">
            <div class="banner-area swiper-container">
                <div class="swiper-wrapper" id="bannerArea">

                </div>
            </div>
            <div class="fixed-banner-area">

            </div>
            <div class="coupon-list">
                <p class="coupon-list-desc"></p>
                <div id="couponList1"></div>
            </div>
        </div>

        <div class="cate-section">
            <div class="coupon-list">
                <div id="couponList2"></div>
            </div>
        </div>

        <p class="txt-loading" style="background-color: #fff;">努力加载中...</p>

        <div class="search-fixed"><a href="/sale/search"><i></i></a></div>
    </div>

    <input type="hidden" id="noDock" value="1" />
    <script type="text/javascript" src="http://cdn.bootcss.com/Swiper/3.4.1/js/swiper.min.js"></script>
    <script type="text/javascript">
        Zepto(function ($) {
            FastClick.attach(document.body);

            var recommendSection = $('.recommend-section'),
                cateSection = $('.cate-section'),
                sortOptionArea = $('.sort-option-area'),
                couponList1 = $('#couponList1'),
                couponList2 = $('#couponList2'),
                couponListDesc = $('.coupon-list-desc'),
                loadingTxt = $('.txt-loading'),
                bannerArea = $('#bannerArea'),
                fixedBannerArea = $('.fixed-banner-area'),
                menu = $('.top-menu .inner');

            var page = 0, pagesize = 20, load = 1, cate = 0, sort = 0;
            var channel = 35,
                banner = [{ "element_id": 2318, "element_type": "webview", "title": "天猫618主会场", "subtitle": "", "extend": "https://s.click.taobao.com/3x0OJiw", "pic": "http://omqxp8we2.bkt.clouddn.com/element/2017/06/13/55321593f5cd40e6c3", "pic2": "", "pic_width": 900, "pic_height": 288, "index": 90, "is_show_title": 0, "dateline": 1497974399, "coupon_list": [], "topic_list": [] }, { "element_id": 2334, "element_type": "webview", "title": "酷暑夏日有它就够 防晒晴雨伞 低至3折等你来抢", "subtitle": "", "extend": "http://m.ibantang.com/zhekou/topic/726/?style=2", "pic": "http://omqxp8we2.bkt.clouddn.com/element/2017/06/13/57392593f974db27d7", "pic2": "", "pic_width": 900, "pic_height": 288, "index": 87, "is_show_title": 0, "dateline": 1497628799, "coupon_list": [], "topic_list": [] }, { "element_id": 2317, "element_type": "webview", "title": "天猫618-天猫超市预热", "subtitle": "", "extend": "https://s.click.taobao.com/p5UQJiw", "pic": "http://omqxp8we2.bkt.clouddn.com/element/2017/06/13/77039593f59d811eab", "pic2": "", "pic_width": 900, "pic_height": 288, "index": 86, "is_show_title": 0, "dateline": 1497715199, "coupon_list": [], "topic_list": [] }, { "element_id": 2258, "element_type": "webview", "title": "天猫618-3C好货抢先GO", "subtitle": "", "extend": "https://s.click.taobao.com/w56wLiw", "pic": "http://omqxp8we2.bkt.clouddn.com/element/2017/06/12/85457593e46936cc3d", "pic2": "", "pic_width": 900, "pic_height": 288, "index": 84, "is_show_title": 0, "dateline": 1497542399, "coupon_list": [], "topic_list": [] }, { "element_id": 2257, "element_type": "webview", "title": "超高颜值移动电源 超低价格5折抢", "subtitle": "", "extend": "http://m.ibantang.com/zhekou/topic/721/?style=2", "pic": "http://omqxp8we2.bkt.clouddn.com/element/2017/06/12/38070593e451739e07", "pic2": "", "pic_width": 900, "pic_height": 288, "index": 83, "is_show_title": 0, "dateline": 1497542399, "coupon_list": [], "topic_list": [] }, { "element_id": 2053, "element_type": "webview", "title": "618提前放血，领券下单立减100元！", "subtitle": "", "extend": "http://m.ibantang.com/zhekou/topic/627/?style=2", "pic": "http://omqxp8we2.bkt.clouddn.com/element/2017/06/08/958685938ccd0b5a8e", "pic2": "", "pic_width": 900, "pic_height": 288, "index": 75, "is_show_title": 0, "dateline": 1497715200, "coupon_list": [], "topic_list": [] }, { "element_id": 1870, "element_type": "webview", "title": "征服时光 美靠眼妆", "subtitle": "", "extend": "http://m.ibantang.com/zhekou/topic/479/?style=2", "pic": "http://omqxp8we2.bkt.clouddn.com/element/2017/06/01/95557592ff073f40cc", "pic2": "", "pic_width": 900, "pic_height": 288, "index": 66, "is_show_title": 0, "dateline": 1499097600, "coupon_list": [], "topic_list": [] }],
                fixedBanner = [{ "element_id": 1149, "element_type": "webview", "title": "9块9包邮", "subtitle": "", "extend": "/sale/Nine", "pic": "http://omqxp8we2.bkt.clouddn.com/element/2017/06/13/62051593f56f578209", "pic2": "http://omqxp8we2.bkt.clouddn.com/element/2017/06/13/32511593f56f5a1775", "pic_width": 600, "pic_height": 680, "index": 10, "is_show_title": 1, "dateline": 1514736000, "coupon_list": [], "topic_list": [] }, { "element_id": 1152, "element_type": "webview", "title": "爆款热销", "subtitle": "", "extend": "/sale/last/", "pic": "http://omqxp8we2.bkt.clouddn.com/element/2017/06/13/52203593f6412243da", "pic2": "http://omqxp8we2.bkt.clouddn.com/element/2017/06/13/96900593f6412581d6", "pic_width": 896, "pic_height": 300, "index": 8, "is_show_title": 1, "dateline": 1514736000, "coupon_list": [], "topic_list": [] }, { "element_id": 1150, "element_type": "webview", "title": "限时特价", "subtitle": "", "extend": "http://m.ibantang.com/zhekou/topic/696/?style=2&channel=72", "pic": "http://omqxp8we2.bkt.clouddn.com/element/2017/06/12/35465593e6ad0d1963", "pic2": "http://omqxp8we2.bkt.clouddn.com/element/2017/06/12/47769593e6ad10e09a", "pic_width": 470, "pic_height": 398, "index": 6, "is_show_title": 1, "dateline": 1514736000, "coupon_list": [], "topic_list": [] }, { "element_id": 1154, "element_type": "webview", "title": "签到", "subtitle": "", "extend": "http://m.ibantang.com/zhekou/signin", "pic": "http://omqxp8we2.bkt.clouddn.com/element/2017/06/13/75102593f6444cc7bf", "pic2": "http://omqxp8we2.bkt.clouddn.com/element/2017/06/13/52685593f6444ec3c2", "pic_width": 470, "pic_height": 399, "index": 4, "is_show_title": 1, "dateline": 1514736000, "coupon_list": [], "topic_list": [] }];

            var _w = $('.wrapper').width(), picH = (_w - 25) / 2;

            var qs = Util.getQueryString(window.location.href);

            //cate
            $('.top-menu .top-menu-item').on('click', function () {
                var _this = $(this);
                if (!_this.hasClass('active')) {
                    $('.top-menu .top-menu-item.active').removeClass('active');
                    _this.addClass('active');

                    var l = _this.offset().left - menu.offset().left;
                    menu.scrollLeft(menu.scrollLeft() + l - _w / 2 + 20);

                    cate = _this.data('cate-id');
                    if (cate == 0) {
                        sortOptionArea.css('display', 'none');
                        cateSection.css('display', 'none');
                        recommendSection.css('display', 'block');
                    } else {
                        sortOptionArea.css('display', 'block');
                        recommendSection.css('display', 'none');
                        cateSection.css('display', 'block');
                    }

                    sort = 0;
                    $('.sort-option-area li.active').removeClass('active');
                    $($('.sort-option-area li')[0]).addClass('active');

                    page = 0;
                    load = 1;

                    couponList1.html('');
                    couponList2.html('');

                    $('body').scrollTop(0);
                    loadingTxt.html('努力获取中...');
                    getProductList();
                }
            });

            //sort
            $('.sort-option-area li').on('click', function () {
                var _this = $(this);
                if (!_this.hasClass('active')) {
                    $('.sort-option-area li.active').removeClass('active');
                    _this.addClass('active');

                    sort = _this.data('type');
                    page = 0;
                    load = 1;

                    couponList2.html('');
                    $('body').scrollTop(0);
                    loadingTxt.html('努力获取中...');
                    getProductList();
                }
            });

            //banner
            if (!(1 * qs.bh)) {
                var bannerHtml = '';
                for (var i = 0; i < banner.length; i++) {
                    var b = banner[i];
                    if (b.element_type != 'webview') {
                        continue;
                    }
                    bannerHtml += '<a data-back-url="' + b.extend + '" href="' + b.extend + '" class="swiper-slide">';
                    bannerHtml += '<img class="lazy" data-original="' + b.pic + '">';
                    bannerHtml += '</a>';
                }
                bannerArea.css('height', (_w * 240 / 750) + 'px').html(bannerHtml);
                var sw = new Swiper('.swiper-container', {
                    autoplay: banner.length > 1 ? 3000 : false,
                    loop: true,
                    pagination: '.swiper-pager'
                });
            }

            //fixed banner
            if (!(1 * qs.fh)) {
                var fixedBannerHtml = '';
                var fb_h = _w * 340 / 750;
                for (var i = 0; i < (fixedBanner.length > 4 ? 4 : fixedBanner.length) ; i++) {
                    var b = fixedBanner[i];
                    if (b.element_type != 'webview') {
                        continue;
                    }
                    var s = '';
                    switch (i * 1) {
                        case 0:
                            s = 'width:' + (fb_h * 300 / 340 - 1) + 'px;height:' + fb_h + 'px;border-right:1px solid #eee;'
                            break;
                        case 1:
                            s = 'width:' + (_w - fb_h * 300 / 340) + 'px;height:' + ((_w - fb_h * 300 / 340) * 170 / 450 - 1) + 'px;border-bottom:1px solid #eee;'
                            break;
                        case 2:
                            s = 'width:' + ((_w - fb_h * 300 / 340) / 2 - 1) + 'px;height:' + (fb_h - (_w - fb_h * 300 / 340) * 170 / 450) + 'px;border-right:1px solid #eee;'
                            break;
                        case 3:
                            s = 'width:' + (_w - fb_h * 300 / 340) / 2 + 'px;height:' + (fb_h - (_w - fb_h * 300 / 340) * 170 / 450) + 'px;'
                            break;
                    }
                    fixedBannerHtml += '<a data-back-url="' + b.extend + '" href="' + b.extend + '" class="fixed-banner-item fbi' + i + '" style="' + s + '">';
                    fixedBannerHtml += '<img class="lazy" data-original="' + b.pic + '">';
                    fixedBannerHtml += '</a>';
                }
                fixedBannerArea.css('height', fb_h + 'px').html(fixedBannerHtml);
            }

            couponListDesc.html('<b></b><i></i><span>每天早10点 · 晚8点上新</span><i></i><b></b>');

            Util.lazyLoad('lazy');
            backUrlEvent();

            if (qs.dt && qs.dt != 1) {
                qs.dt = qs.dt * 1;
                if (qs.dt >= 1 && qs.dt <= $('.top-menu .top-menu-item').length) {
                    $($('.top-menu .top-menu-item')[qs.dt - 1]).trigger('click');
                }
            } else {
                getProductList();
            }

            var de = document.documentElement;
            $(document).on('scroll', function () {
                var sH = de.scrollHeight, cH = de.clientHeight;
                if (sH - cH - $('body').scrollTop() <= 400) {
                    getProductList();
                }
            });

            function getProductList() {
                if (!load) {
                    return;
                }
                $.ajax({
                    url: '/sale/getZhekouListByCate',
                    type: 'Post',
                    dataType: 'json',
                    data: {
                        'limit': page,
                        'pagesize': pagesize,
                        'cid': cate,
                        'sort': sort,
                        'Key': channel
                    },
                    beforeSend: function () {
                        load = 0;
                    },
                    success: function (data) {
                        if (data.rows.CurrentPageList != null) {
                            createProductList(data.rows.CurrentPageList);
                            if (data.rows.CurrentPageList.length >= pagesize) {

                                page++;
                                load = 1;
                            } else {
                                loadingTxt.html('没有更多商品了');
                            }
                        }
                    }
                });
            }

            function createProductList(clist) {
                if (cate == 0) {
                    var htmlstr = '';
                    for (var i = 0, len = clist.length; i < len; i++) {
                        //if (clist[i].feed_type != 1) {
                        //    continue;
                        //}
                        var zk = clist[i];
                        var platform = '', platformstr = '';
                        switch (zk.userType * 1) {
                            case 2:
                                platform = '淘宝';
                                platformstr = 'taobao';
                                break;
                            case 1:
                                platform = '天猫';
                                platformstr = 'tmall';
                                break;
                        }
                        htmlstr += '<a data-back-url="' + zk.auctionId + '" href="/goods/' + zk.auctionId + '.html">';
                        htmlstr += '<div class="coupon-card-v2">';
                        htmlstr += '<div class="pic-area lazy new" data-original="' + zk.pictUrl + '"></div>';
                        htmlstr += '<div class="info-area">';
                        htmlstr += '<div class="info-top">';
                        htmlstr += '<p class="title">' + zk.title + '</p>';
                        htmlstr += '<p class="stat">';
                        if (zk.post_free) {
                            htmlstr += '<span class="platform ' + platformstr + '"></span>';
                        }
                        htmlstr += platform + '价&nbsp;&yen;' + zk.zkPrice + '</p>';
                        htmlstr += '</div>';
                        htmlstr += '<div class="info-bottom">';
                        htmlstr += '<div class="price-area">';
                        htmlstr += '<span class="qhj">券后价</span>';
                        htmlstr += '<span class="yen">&yen;</span><span class="price number-font">' + (zk.zkPrice - zk.couponAmount).toFixed(1) + '</span>';
                        htmlstr += '<span class="quan-btn"><em class="number-font">' + zk.couponAmount + '</em>元券</span>';
                        htmlstr += '</div>';
                        htmlstr += '<div class="progress-area">';
                        htmlstr += '<span class="pro-desc">已领' + Math.floor(0.48 * 100) + '%</span>';
                        htmlstr += '<div class="pro-container"><div class="pro" style="width:' + Math.floor(0.48 * 100) + '%;"></div>';
                        htmlstr += '</div>';
                        htmlstr += '</div>';
                        htmlstr += '</div>';
                        htmlstr += '</div>';
                        htmlstr += '</div>';
                        htmlstr += '</a>';
                    }
                    couponList1.append(htmlstr);
                } else {
                    var htmlstr = '';
                    for (var i = 0, len = clist.length; i < len; i++) {
                        var zk = clist[i];
                        htmlstr += '<a data-back-url="' + zk.auctionId + '" href="/goods/' + zk.auctionId + '.html">';
                        htmlstr += '<div class="product-item-t2" style="width:' + picH + 'px;">';
                        htmlstr += '<div class="pic lazy new" data-original="' + zk.pictUrl + '" style="width: ' + picH + 'px; height: ' + picH + 'px;"></div>';
                        htmlstr += '<p class="title">';
                        //if (zk.post_free == 1) {
                        htmlstr += '<span class="post-free">包邮</span>&nbsp;';
                        // }
                        htmlstr += zk.title + '</p>';

                        htmlstr += '<div class="progress-area">';
                        htmlstr += '<p class="pro-text">已领' + Math.floor(0.48 * 100) + '%</p>';
                        htmlstr += '<div class="pro-container">';
                        htmlstr += '<div data-pro="0.48" class="pro" style="width:' + Math.floor(0.48 * 100) + '%;"></div>';
                        htmlstr += '</div>';
                        htmlstr += '</div>';

                        htmlstr += '<div class="price-area">';
                        htmlstr += '<p class="gap-price"><em class="number-font">' + zk.couponAmount + '</em>元券</p>';
                        htmlstr += '<p class="price">券后价&yen;<em class="number-font">' + (zk.zkPrice - zk.couponAmount).toFixed(1) + '</em></p>';
                        htmlstr += '</div>';
                        htmlstr += '</div>';
                        htmlstr += '</a>';
                    }
                    couponList2.append(htmlstr);
                }
                backUrlEvent();
                Util.lazyLoad('lazy.new');
                $('.lazy.new').removeClass('new');
            }

            function backUrlEvent() {
                if (qs && qs.bu == 1) {
                    $('[data-back-url]').on('click', function (e) {
                        e.preventDefault();
                        var url = $(this).data('back-url');
                        window.location.href = '/zhekou/pagewithback/?u=' + encodeURIComponent(url);
                    });
                }
            }
        });
    </script>
</body>
</html>
